package com.linQing.waterWork.controller;

import com.linQing.waterWork.annotation.RepeatSubmitLimit;
import com.linQing.waterWork.modle.dto.PageEventHistoryDto;
import com.linQing.waterWork.modle.page.TableDataInfo;
import com.linQing.waterWork.modle.vo.EventHistoryListVo;
import com.linQing.waterWork.modle.vo.EventInfoListVo;
import com.linQing.waterWork.service.sql.SwsEventinfoService;
import com.linQing.waterWork.service.sql.SwsEventjkhistoryService;
import com.linQing.waterWork.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

import static com.linQing.waterWork.web.JsonResult.getDataTable;
import static com.linQing.waterWork.web.JsonResult.ok;

@Api(value = "报警信息模块", tags = "报警信息模块")
@RestController
@Validated
@RequestMapping("/event")
public class EventController {

    @Autowired
    private SwsEventjkhistoryService service;

    @Autowired
    private SwsEventinfoService swsEventinfoService;

    @ApiOperation("查询历史报警信息")
    @PostMapping("/history")
    @RepeatSubmitLimit(businessKey = "pageAllToHistory", businessParam = "#pageAllToHistory", time = 10)
    public JsonResult<TableDataInfo> pageAllToHistory( @RequestBody PageEventHistoryDto pageEventHistoryDto) {
        int pageNum = pageEventHistoryDto.getPageNum();
        int pageSize = pageEventHistoryDto.getPageSize();
        List<EventHistoryListVo> list = service.selectEventHistory(pageEventHistoryDto);
        return ok(getDataTable(list, list.size() > 0 ? list.get(0).getTotal() : 0, pageSize, pageNum));
    }

    @ApiOperation("查询实时报警信息")
    @GetMapping("/info")
    public JsonResult<List<EventInfoListVo>> pageAll(String EquipmentID) {
        return ok(swsEventinfoService.selectEventInfoVo(EquipmentID));
    }

    @ApiOperation("导出报警信息")
    @PostMapping("/export")
    @RepeatSubmitLimit(businessKey = "pageAllToInfo", businessParam = "#pageAllToInfo", time = 10)
    public void export(@RequestBody PageEventHistoryDto pageEventHistoryDto, HttpServletResponse response) throws IOException {
        service.export(pageEventHistoryDto, response);
    }

}
